import spock.lang.Specification

/**
 * Created at 2017/10/13 14:55
 * @author gongweixin
 */
class LimitExample extends Specification {

    def "test map sort limit"() {
        def map = [1:1, 2:2, 3:3, 4:4]
        map = map.sort { -it.key }.take(2)
        expect:
        map == [4:4, 3:3]
    }

    def "test map sort limit than size"() {
        def map = [1:1, 2:2, 3:3, 4:4]
        map = map.sort { -it.key }.take(8)
        expect:
        map == [4:4, 3:3, 2:2, 1:1]
    }

}
